<script lang="ts" setup>
interface Props {
	show: boolean; // 是否显示模态框
	closeOnClickModal?: boolean; // 是否点击遮罩关闭
}
interface Emits {
	(e: "update:show", show: boolean): void;
	(e: "close"): void;
}
const props = withDefaults(defineProps<Props>(), { closeOnClickModal: true });
const emits = defineEmits<Emits>();
// 点击模糊区域
const markClick = () => {
	if (props.closeOnClickModal) {
		emits("update:show", false);
		emits("close");
	}
};
</script>

<template>
	<Teleport to="body">
		<Transition name="fade">
			<dialog class="my-dialog" v-show="show" @click.stop="markClick()">
				<slot></slot>
			</dialog>
		</Transition>
	</Teleport>
</template>

<style lang="scss" scoped>
.fade-enter-from {
	opacity: 0;
}
.fade-enter-active {
	transition: all 0.2s;
}
.fade-leave-to {
	opacity: 0;
}
.fade-leave-active {
	position: absolute;
	transition: all 0.2s;
}
.my-dialog {
	position: fixed;
	top: 0;
	left: 0;
	margin: 0;
	padding: 0;
	width: 100vw;
	height: 100vh;
	border: none;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	background-color: #00000088;
}
</style>
